<template>
  <d2-container>
    <div class="d2-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>房产管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-form :inline="true" class="SearchForm">
      <el-form-item>
        <router-link to="/house/add">
          <el-button type="success">新增房产</el-button>
        </router-link>
      </el-form-item>
      <el-form-item label="园区名称">
        <el-input
          placeholder="请输入"
          type="text"
          v-model.trim="searchForm.gardenName"
        ></el-input>
      </el-form-item>
      <el-form-item label="房东姓名">
        <el-input
          placeholder="请输入"
          type="text"
          v-model.trim="searchForm.masterName"
        ></el-input>
      </el-form-item>
      <el-form-item label="房东手机号">
        <el-input
          placeholder="请输入"
          type="text"
          v-model.trim="searchForm.masterPhone"
        ></el-input>
      </el-form-item>
      <el-form-item label="经纪人手机号">
        <el-input
          placeholder="请输入"
          type="text"
          v-model.trim="searchForm.agentName"
        ></el-input>
      </el-form-item>
      <el-form-item label="地址(省)">
        <el-input
          placeholder="请输入"
          type="text"
          v-model.trim="searchForm.province"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="地址(市)">
        <el-input
          placeholder="请输入"
          type="text"
          v-model.trim="searchForm.city"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="地址(县/区)">
        <el-input
          placeholder="请输入"
          type="text"
          v-model.trim="searchForm.county"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="详细地址">
        <el-input
          placeholder="请输入"
          type="text"
          v-model.trim="searchForm.address"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="租用状态">
        <el-select v-model="searchForm.rentStatus" placeholder="请选择">
          <el-option label="未出租" :value="0"></el-option>
          <el-option label="已出租" :value="1"></el-option>
          <el-option label="正在出租" :value="2"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="上架状态">
        <el-select v-model="searchForm.shelfStatus" placeholder="请选择">
          <el-option label="未上架" :value="0"></el-option>
          <el-option label="上架" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="添加时间">
        <el-date-picker
          v-model="searchForm.createTime"
          type="datetime"
          placeholder="选择日期时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-button type="primary" @click="search()" icon="el-icon-search"
        >查询</el-button
      >
      <el-button type="danger" icon="el-icon-refresh" @click="reset"
        >重置</el-button
      >
    </el-form>

    <el-table border :data="tableData.list">
      <el-table-column
        label="房产id"
        align="center"
        prop="id"
      ></el-table-column>
      <el-table-column
        label="园区名称"
        align="center"
        prop="gardenName"
      ></el-table-column>
      <el-table-column
        label="房东UID"
        align="center"
        prop="housingMasterId"
      ></el-table-column>
      <el-table-column
        label="房东姓名"
        align="center"
        prop="masterName"
      ></el-table-column>
      <el-table-column
        label="房东手机号"
        align="center"
        prop="masterPhone"
      ></el-table-column>
      <el-table-column label="地址" align="center">
        <template slot-scope="scope">
          {{ `${scope.row.province},${scope.row.city},${scope.row.county}` }}
        </template>
      </el-table-column>
      <el-table-column
        label="详情地址"
        align="center"
        prop="address"
      ></el-table-column>
      <el-table-column
        label="面积"
        align="center"
        prop="houseArea"
      ></el-table-column>
      <el-table-column label="房源类型" align="center" prop="title">
        <template slot-scope="scope">
          {{
            ["", "园区", "写字楼", "商铺", "厂房", "仓库", "土地"][
              scope.row.houseType
            ]
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="房源经纪人名称"
        align="center"
        prop="agentName"
      ></el-table-column>
      <el-table-column
        label="房源经纪人联系方式"
        align="center"
        prop="masterPhone"
      ></el-table-column>
      <el-table-column
        label="关联园区名称"
        align="center"
        prop="gardenName"
      ></el-table-column>
      <el-table-column label="房产状态" align="center" prop="title">
        <template slot-scope="scope">
          {{ ["未出租", "已出租", "正在出租"][scope.row.rentStatus] }}
        </template>
      </el-table-column>
      <el-table-column label="添加时间" align="center" prop="create_time">
        <template slot-scope="scope">
          {{ $moment(scope.row.createTime).format("YYYY-MM-DD hh:mm:ss") }}
        </template>
      </el-table-column>
      <el-table-column label="上架状态" align="center">
        <template slot-scope="scope">
          {{ [ "未上架", "上架"][scope.row.shelfStatus] }}
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" fixed="right">
        <template slot-scope="scope">
          <router-link :to="`/house/edit/${scope.row.id}`">
            <el-button type="text">查看/编辑</el-button>
          </router-link>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="search"
      @current-change="search"
      :current-page.sync="page"
      :page-sizes="[10, 25, 50, 100]"
      :page-size.sync="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tableData.total"
    ></el-pagination>
  </d2-container>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      searchForm: {},
      tableData: {
        list: [],
        total: 0,
      },
      page: 1,
      pageSize: 10,
    };
  },
  methods: {
    search() {
      let params = {
        pageNum: this.page,
        pageSize: this.pageSize,
        ...this.searchForm,
      };
      if (params.createTime) {
        params.createTime = new Date(
          Date.parse(new Date(params.createTime)) + 8 * 3600 * 1000
        );
      }

      this.$axios.post("/wxHousingAssess/list", params).then((result) => {
        if (result) {
          this.tableData = {
            list: result.data.list,
            total: result.data.total,
          };
        } else {
          this.$message.error(result.data.msg);
        }
      });
    },
    reset() {
      this.searchForm = {};
      this.search();
    },
  },
  created() {
    this.search();
  },
};
</script>

<style scoped lang="scss">
</style>
